package pATT.profilingAlgorithm.PersonalSearcher;
/***************************************************************************
 *                            AbstractVectorCreator                        * 
 *                       initial version by: Travis Bauer                  *
 *                      copyright (C) 2001 IGLU Research Group             *
 *                             trbauer@indiana.edu                         *
 ***************************************************************************/
/***************************************************************************
 * The licence for this code is included in LICENSE.txt.  If you did not   *
 * get this file with this distribution, request a copy from               *
 * iglu@cs.indiana.edu                                                     *
 ***************************************************************************/

/**
 * Implements some of the functionality of the vector creator and provides
 * a convienence method for making produced vectors conform to the
 * user's limitations on them.
 *
 * @author <a href="mailto:trbauer@indiana.edu">Travis Bauer</a>
 * @author <a href="mailto:rscherle@indiana.edu">Ryan Scherle</a>
 */
public abstract class AbstractVectorCreator implements VectorCreator {

  private TermVector dictionary = null;
  private boolean linearlyScale = false;
  private boolean normalize = false;
  private int maxSize=-1;

  /////////////////////////////////////////////////////////////////
  /**
     Set a dictionary controlling the vocabulary allowed in this vector.
     Only terms occuring in the dictionary will appear in the resultant
     vector.
  **/
  public void setDictionary(TermVector dict) {
    dictionary = dict;
  }

  /////////////////////////////////////////////////////////////////
  public void setLinearlyScale(boolean scale) {
    linearlyScale = scale;
  }

  /////////////////////////////////////////////////////////////////
  public void setNormalize(boolean normalize) {
    this.normalize = normalize;
  }

  /////////////////////////////////////////////////////////////////
  public void setMaxSize(int n) {
    maxSize = n;
  }
  
  /////////////////////////////////////////////////////////////////
  /**
   * Alter a vector to conform to the settings made here.  Subclasses of this
   * class should run this method on their vector before returning it.
   *
   * @param candidate a <code>TermVector</code> value
   * @return a <code>TermVector</code> value
   */
  protected void cleanUp(TermVector candidate) {
    if (dictionary!=null)
      {
	TermVector remWords = (TermVector)candidate.clone();
	remWords.subtract(dictionary);
	candidate.subtract(remWords);
      }
    if (maxSize!=-1) candidate.truncateTo(maxSize);
    if (linearlyScale) candidate.linearlyScale();
    if (normalize) candidate.normalizeSquare();
  }
  
}
